﻿using System;
using Microsoft.Phone.Shell;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PhoneCore.Framework;
using PhoneCore.Framework.Bootstrap;
using PhoneCore.Framework.Configuration;
using PhoneCore.Framework.Diagnostic.Tracing;
using PhoneCore.Framework.IoC;
using SecureBox.UI.Infrastructure.Plugins;

namespace SecureBox.UI.UnitTests.Core
{
    [TestClass]
    public class SystemTests
    {
  
        [TestMethod]
        public void CanRegisterBootstrapper()
        {
            using (IContainer container = TestHelper.GetContainer())
            {
                container.RegisterType(typeof (IBootstrapperService), typeof (BootstrapperService),
                                   ConfigSettings.Instance.GetSection("system/bootstrapping"));
                IBootstrapperService service = container.Resolve<IBootstrapperService>();
                service.Run();

                Action<Type> checkPlugin = type =>
                                               {
                                                   var plugin = service.GetPlugin(type);
                                                   Assert.IsNotNull(plugin,String.Format("Unable to get plugin of type '{0}'",type));
                                               };

                checkPlugin(typeof (CoreBootstrapperPlugin));
                checkPlugin(typeof (InitPlugin));
                checkPlugin(typeof (DataContextPlugin));
                checkPlugin(typeof (PassGenPlugin));
            }
        }

        [TestMethod]
        public void CanGetTraceReport()
        {
            DefaultTraceController controller = new DefaultTraceController(TraceFactory.GetTrace() as DefaultTrace, "Resources/DefaultTraceReport.txt");
            var writer = controller.GenerateReport();
            string s = writer.ToString();
            Assert.IsNotNull(s);
            Assert.AreNotSame(String.Empty, s);
        }
    }
}
